program main
    implicit none
    integer,parameter :: limit=50
    integer :: square(1:limit,1:limit,0:limit),flag(1:limit,1:limit)
    integer :: i,j,k
    integer,external :: isqrt
    forall(i=1:limit,j=1:limit) square(i,j,0)=i**2+j**2
    forall(i=1:limit,j=1:limit,k=1:limit) square(i,j,k)=k**2
    forall(i=1:limit,j=1:limit,i<=j) flag(i,j)=count(square(i,j,0)==square(i,j,1:))
    do i=1,limit
        do j=i,limit
            if( flag(i,j)/=0 )then
                k=isqrt(square(i,j,0))
                write(*,10)i,j,k
            end if
        end do
    end do
10  format(i3,'^2+',i3,'^2=',i3,'^2')
end program
function isqrt(n)
    implicit none
    integer :: n,isqrt
    isqrt=0
    do while(isqrt**2 /= n)
        isqrt=isqrt+1
    end do
end function
